import { isUrl } from '../utils/utils';

let menuData = [
  {
    key: '1',
    name: '老师管理',
    path: 'admin/teacher',
    children: [
      {
        name: '老师列表',
        path: 'index'
      },
      {
        name: '老师课程',
        path: 'course'
      }

    ]
  }
];


function formatter(data, parentPath = '/', parentAuthority) {
  return data.map(item => {
    let { path } = item;
    if (!isUrl(path)) {
      path = parentPath + item.path;
    }
    const result = {
      ...item,
      path,
      authority: item.authority || parentAuthority,
    };
    if (item.children) {
      result.children = formatter(item.children, `${parentPath}${item.path}/`, item.authority);
    }
    return result;
  });
}

let menu = formatter(menuData);

export default menu;